package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hql
 * @date 2019-12-08 19:33
 */
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    /**
     * 判断是否存在会员
     * @param telphone 手机号
     * @return
     */
    @Override
    public Member checkTelphone(String telphone) {
       Member member = memberDao.checkTelphone(telphone);
        return member;
    }

    /**
     *添加会员信息
     * @param member 会员信息
     */
    @Override
    public void addMember(Member member) {
        memberDao.addMember(member);
    }

    /**
     * 查询到当前月份为止所有的会员数
     * @param list 月份集合
     * @return
     */
    @Override
    public List<Integer> getMemberReport(List<String> list) {
        List<Integer> countList = new ArrayList<>();

        for (String month : list) {
            StringBuilder sb =  new StringBuilder();
            sb.append(month).append(".31");
            String mon=sb.toString();
            System.out.println(mon);
            Integer count = memberDao.getMemberReport(mon);
            countList.add(count);
        }
        return countList;
    }

    /**
     * 查询今天注册的会员数
     * @param reportDate
     * @return
     */
    @Override
    public Integer findByTodayNewMember(String reportDate) {
      Integer i =   memberDao.findByTodayNewMember(reportDate);
      return i;
    }

    /**
     * 查询总会员数
     * @return
     */
    @Override
    public Integer findAllMember() {
        Integer memberCount = memberDao.findAllMember();
        return memberCount;
    }

    /**
     * 这周注册的会员数
     * @param firstDayOfWeek
     * @return
     */
    @Override
    public Integer findThisWeekNewMember(String firstDayOfWeek) {

        Integer memberCount = memberDao.findThisWeekNewMember(firstDayOfWeek);
        return memberCount;
    }
}
